﻿package gases.as3.librarys.core.utils
{
	import flash.events.EventDispatcher;
	import flash.net.SharedObject;
	
	/**
	 * FLASH COOKIES flash本地记录信息保存适用于少量信息的本地保存 例如登录时的用户名保存
	 * @author 
	 */
	public class FlashCookies extends EventDispatcher
	{
		private var _cookie:SharedObject;
		private var _cookieName:String;
		
		public function FlashCookies(name:String) 
		{
			_cookieName = name;
			super();
		}
		
		override protected function init():void 
		{
			super.init();
			_cookie = SharedObject.getLocal(_cookieName);
		
		}
		
		/**
		 * 保存COOKIES
		 * @param	key cookie标签
		 * @param	d 对应的值
		 */
		public function saveCookies(key:String, d:Object):void
		{
			_cookie.data[key] = d;
			_cookie.flush();
		}
		
		/**
		 * 获得Cookies
		 */
		public function get cookies():SharedObject
		{
			return _cookie;
		}
		
		/**
		 * 获得本地保存的值
		 * @param	key 保存的键
		 * @return 返回一个值
		 */
		public function getData(key:String):Object
		{
			return _cookie.data[key];
		}
		
		/**
		 * 清空本地保存信息
		 */
		public function clear():void
		{
			_cookie.clear();
		}
		
		override public function dispose():void
		{
			_cookie = null;
			super.dispose();
		}
		
	}

}